import gtk, gtk.glade
import widgets
import ftpmod
import localmod
import assistant
import log_act
import local_tree

def locations(self):
    self.gladefile = gtk.glade.XML("absynth-ftp.glade", "AbsynthFull")
    widgets.define_widgets(self, self.gladefile)

def mods(self):
    self.connection = ftpmod.AbsynthModFTP()
    self.local = localmod.AbsynthModLocal()
    self.assistant = assistant
    
    try:
        import notify
        self.notify = notify.Notify()
    except: 
        print "Libnotify non disponibile"
    
def systray(self):
    self.status = gtk.StatusIcon()
    self.status.set_tooltip("Absynth FTP")
    self.status.set_from_stock("gtk-network")
    self.status.connect("popup_menu", self.tray_show_menu)
    
def treeview_remote(self):
    self.remote_treemodel = gtk.ListStore(str, str, str, str, str)
    self.remote_treeview.set_model(self.remote_treemodel)
    self.remote_treeview.set_headers_visible(True)
    
    #test filetype column
    renderer=gtk.CellRendererText()
    self.type_column=gtk.TreeViewColumn("Filename", renderer, text=0)
    #self.type_column.set_visible(0)
    self.remote_treeview.append_column(self.type_column)
    #filetype column
    renderer=gtk.CellRendererPixbuf()
    self.image_column=gtk.TreeViewColumn("T", renderer, icon_name=1)
    self.image_column.set_resizable(False)
    self.remote_treeview.append_column(self.image_column)
    #filename column
    renderer=gtk.CellRendererText()
    self.title_column=gtk.TreeViewColumn("Filename", renderer, text=2)
    self.title_column.set_resizable(True)
    self.title_column.set_sort_column_id(1)
    self.remote_treeview.append_column(self.title_column)
    #size column
    renderer=gtk.CellRendererText()
    self.size_column=gtk.TreeViewColumn("Size", renderer, text=3)
    self.size_column.set_resizable(True)
    self.size_column.set_sort_column_id(2)
    self.remote_treeview.append_column(self.size_column)
    #mtime column
    renderer=gtk.CellRendererText()
    self.mtime_column=gtk.TreeViewColumn("Last edited", renderer, text=4)
    self.mtime_column.set_resizable(True)
    self.mtime_column.set_sort_column_id(3)
    self.remote_treeview.append_column(self.mtime_column)
    
def treeview_local(self):
    self.local_treemodel = gtk.ListStore(str, str, str, str, str)
    self.local_treeview.set_model(self.local_treemodel)
    self.local_treeview.set_headers_visible(True)
    
    #test filetype column
    renderer=gtk.CellRendererText()
    self.type_column=gtk.TreeViewColumn("Filename", renderer, text=0)
    #self.type_column.set_visible(0)
    self.local_treeview.append_column(self.type_column)
    #filetype column
    renderer=gtk.CellRendererPixbuf()
    self.image_column=gtk.TreeViewColumn("T", renderer, icon_name=1)
    self.image_column.set_resizable(False)
    self.local_treeview.append_column(self.image_column)
    #filename column
    renderer=gtk.CellRendererText()
    self.title_column=gtk.TreeViewColumn("Filename", renderer, text=2)
    self.title_column.set_resizable(True)
    self.title_column.set_sort_column_id(1)
    self.local_treeview.append_column(self.title_column)
    #size column
    renderer=gtk.CellRendererText()
    self.size_column=gtk.TreeViewColumn("Size", renderer, text=3)
    self.size_column.set_resizable(True)
    self.size_column.set_sort_column_id(2)
    self.local_treeview.append_column(self.size_column)
    #mtime column
    renderer=gtk.CellRendererText()
    self.mtime_column=gtk.TreeViewColumn("Last edited", renderer, text=4)
    self.mtime_column.set_resizable(True)
    self.mtime_column.set_sort_column_id(3)
    self.local_treeview.append_column(self.mtime_column)
    
    local_tree.populate(self)
    
def treeview_dw(self):
    self.dw_treemodel = gtk.ListStore(str, str, str, str, str)
    self.dw_treeview.set_model(self.dw_treemodel)
    self.dw_treeview.set_headers_visible(True)
    
    #test filetype column
    renderer=gtk.CellRendererText()
    self.type_column=gtk.TreeViewColumn("Filename", renderer, text=0)
    #self.type_column.set_visible(0)
    self.dw_treeview.append_column(self.type_column)
    #filetype column
    renderer=gtk.CellRendererPixbuf()
    self.image_column=gtk.TreeViewColumn("T", renderer, icon_name=1)
    self.image_column.set_resizable(False)
    self.dw_treeview.append_column(self.image_column)
    #filename column
    renderer=gtk.CellRendererText()
    self.title_column=gtk.TreeViewColumn("Filename", renderer, text=2)
    self.title_column.set_resizable(True)
    self.title_column.set_sort_column_id(1)
    self.dw_treeview.append_column(self.title_column)
    #size column
    renderer=gtk.CellRendererText()
    self.size_column=gtk.TreeViewColumn("Size", renderer, text=3)
    self.size_column.set_resizable(True)
    self.size_column.set_sort_column_id(2)
    self.dw_treeview.append_column(self.size_column)
    #mtime column
    renderer=gtk.CellRendererText()
    self.mtime_column=gtk.TreeViewColumn("Downloaded", renderer, text=4)
    self.mtime_column.set_resizable(True)
    self.mtime_column.set_sort_column_id(3)
    self.dw_treeview.append_column(self.mtime_column)
def log_view(self):
    self.log = log_act
    self.log_textbuffer = gtk.TextBuffer(None)
    self.logtextview.set_buffer(self.log_textbuffer)
    
def local_popup(self):
    self.local_popmenu =  gtk.glade.XML("absynth-ftp.glade", "localmenu")
    dic = {
           "on_upload_activate" : self.upload_file,
           "on_reload_activate" : self.local_reload,
           "on_delete_activate" : self.local_delete
           }
    self.local_popmenu.signal_autoconnect(dic)
    
def remote_popup(self):
    self.remote_popmenu =  gtk.glade.XML("absynth-ftp.glade", "remotemenu")
    dic = {
           "on_download_activate" : self.remote_treeview_clicked,
           "on_delete_activate" : self.remote_delete,
           "on_update_activate" : self.remote_update
           }
    self.remote_popmenu.signal_autoconnect(dic)
    
def localpath(self):
    self.update_localpath()